﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DBAccessLibrary.Interface;
using DBAccessLibrary.Model;
using DataAccess;

namespace DBAccessLibrary.Grammar
{
    class MongoDbGrammar : DBGrammar, IGrammar, ILocalGrammar
    {
        public MongoDbGrammar(ConnectionModel connect)
            : base(connect)
        { }

         private string GetTypeFilter(DBType type, FieldEntity field,string sql)
        {
            string typeStr = field.TypeName;
            int columnLength;
            int.TryParse(field.Length, out columnLength);
            string length = field.Length;
            string TypeName = field.TypeName.ToUpper();
           
         
            if (TypeName == "TIMESTAMP" || TypeName == "DATE")
            {
                length = "";
            }
            return string.Format(sql, field.TableName, field.Name, typeStr, length);
        }

        #region IGrammar 成员

        public string AddColumn(Model.FieldEntity filed)
        {
            return string.Empty;
        }

        public IEnumerable<string> EditColumn(Model.FieldEntity filed)
        {
            return new List<string>();
        }

        public IEnumerable<string> RemoveColumn(Model.FieldEntity field)
        {
            return new List<string>();
        }

        public string SelectTop(Model.TableEntity table, int count)
        {
            return string.Empty;
        }


        public string GetChTableSql
        {
           get { return string.Empty; }
        }

        public string IsExistChTableSql
        {
              get { return string.Empty; }
        }

        public string AppendTabText(string text)
        {
           return base.TabText(text);
        }

        public string GetErrorInfo(string errorMsg)
        {
            return string.Empty;
        }

        public string GetProcParamInfo(Model.ProcEntity entity)
        {
           return string.Empty;
        }

        public IEnumerable<string> EditPrimary(Model.TableEntity table)
        {
            return new List<string>();
        }

        protected override string GetProcName(string sql, out string paramStr)
        {
            paramStr = string.Empty;
            return string.Empty;
        }
       

        public string GetPageingSql(string sql, decimal index, decimal count)
        {
            return sql;
        }

        #endregion
    
        #region ILocalGrammar 成员

        public DataAccess.DatabaseType GetConnectionStr(out string connectStr)
        {
            connectStr = _connect.ConnectionStr;

            return DatabaseType.MongoDB;
        }

        #endregion
    }
}
